﻿using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

namespace Metro.Kashikoi.ServiceContract.Storage
{
    /// <summary>
    /// This class defines the Bin.
    /// </summary>
    [DataContract(IsReference = true)]
    [Table("BinInventories")]
    public class BinInventory : Inventory
    {
        /// <summary>
        /// Gets or sets quantity of the bin.
        /// </summary>
        /// <value>
        /// The quantity.
        /// </value>
        [DataMember]
        [Range(1, int.MaxValue)]
        [RangeValidator(1, RangeBoundaryType.Inclusive, int.MaxValue, RangeBoundaryType.Inclusive)]
        public int Quantity { get; set; }

        /// <summary>
        /// Gets or sets split quantity of the bin.
        /// </summary>
        /// <value>
        /// The split quantity.
        /// </value>
        [DataMember]
        [Range(1, int.MaxValue)]
        [RangeValidator(1, RangeBoundaryType.Inclusive, int.MaxValue, RangeBoundaryType.Inclusive)]
        public int SplitQuantity { get; set; }

        /// <summary>
        /// Gets or sets unit of the items in the bin.
        /// </summary>
        /// <value>
        /// The unit.
        /// </value>
        [DataMember]
        [Required]
        [StringLength(255, MinimumLength = 1)]
        [StringLengthValidator(1, 255)]
        public string Unit { get; set; }

        /// <summary>
        /// Gets or sets the SSID of the bin.
        /// </summary>
        /// <value>
        /// The SSID.
        /// </value>
        [DataMember]
        [Required]
        [StringLength(255, MinimumLength = 1)]
        [StringLengthValidator(1, 255)]
        public string SSID { get; set; }

        /// <summary>
        /// Gets or sets the stock status code.
        /// </summary>
        /// <value>
        /// The stock status code.
        /// </value>
        [DataMember]
        [Range(0, 3)]
        [RangeValidator(0, RangeBoundaryType.Inclusive, 3, RangeBoundaryType.Inclusive)]
        public int StockStatusCode { get; set; }

        /// <summary>
        /// Gets or sets the stock status.
        /// </summary>
        /// <value>
        /// The stock status.
        /// </value>
        [NotMapped]
        public StockStatus StockStatus
        {
            get
            {
                return (StockStatus)StockStatusCode;
            }
            set
            {
                StockStatusCode = (int)value;
            }
        }

        /// <summary>
        /// Copies the specified to the destination.
        /// </summary>
        /// <param name="destination">The destination.</param>
        public void CopyTo(BinInventory destination)
        {
            destination.Name = this.Name;
            destination.Quantity = this.Quantity;
            destination.SplitQuantity = this.SplitQuantity;
            destination.Unit = this.Unit;
        }

        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>The newly created instance.</returns>
        public BinInventory Clone()
        {
            var inv = new BinInventory
            {
                CategoryId = this.CategoryId,
                ItemId = this.ItemId,
                StockAreaId = this.StockAreaId,
                StockStatus = StockStatus.StockOut,
                Deleted = false,
                Trigger = this.Trigger.Clone(),
            };
            this.CopyTo(inv);
            return inv;
        }
    }
}
